//
//  WSQSelectionViewRoundedRectCell.m
//  RACTest
//
//  Created by 翁胜琼 on 2018/10/12.
//  Copyright © 2018 翁胜琼. All rights reserved.
//

#import "WSQSelectionViewRoundedRectCell.h"
#import "WSQSelectionItem.h"

@interface WSQSelectionViewRoundedRectCell()
{
    CGFloat wsq_fontsize;   // 字体大小
    UIImage *wsq_backgroundImage;   // 背景图片
    UIColor *wsq_backgroundColor;   // 背景颜色
    UIColor *wsq_titleColor;        // 文字颜色
    CGFloat wsq_cornerRadius;   // cell 圆角
}

@property (weak, nonatomic) IBOutlet UIImageView *bgImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (nonatomic,strong) WSQSelectionItem *item;

@end


@implementation WSQSelectionViewRoundedRectCell

- (void)awakeFromNib {
    [super awakeFromNib];

    [self setupUI];
}


- (void)setItem:(WSQSelectionItem *)item
{
    _item = item;
    _titleLabel.text = item.title;
}

// 设置属性
- (void)setTitleColor:(UIColor *)textColor
             fontsize:(CGFloat)fontsize
         cornerRadius:(CGFloat)cornerRadius
        backgroundColor:(UIColor *)bgColor
        backgroundImage:(UIImage *)bgImage
{
    if (textColor != nil)
    {
        self.titleLabel.textColor = textColor;
    }
    
    if (fontsize != 0)
    {
        self.titleLabel.font = [UIFont fontWithName:@"PingFang SC" size:fontsize];
    }
    
    if (cornerRadius != 0)
    {
        self.layer.cornerRadius = cornerRadius;
        self.layer.masksToBounds = true;
    }
    
    if (bgColor != nil)
    {
        self.backgroundColor = bgColor;
    }
    
    if (bgImage != nil)
    {        
        self.bgImageView.image = bgImage;
    }
}

// MARK: - private
- (void)setupUI
{
    [self setDefaultValue];
    // 设置默认属性
    [self setTitleColor:wsq_titleColor
               fontsize:wsq_fontsize
           cornerRadius:wsq_cornerRadius
        backgroundColor:wsq_backgroundColor
        backgroundImage:wsq_backgroundImage];
}

// 设置默认值
- (void)setDefaultValue
{
    wsq_fontsize = 14;
    wsq_backgroundColor = [UIColor whiteColor];
    wsq_backgroundImage = nil;
    wsq_cornerRadius = 0;
}
@end
